#!/usr/bin/python
import os
import signal
import sys
from subprocess import call
import time
logfile = open('reRun.log','w')

def signal_handler(signal, frame):
   print 'You pressed Ctrl+C!'
   logfile.close()
   sys.exit(0)


def main():
   signal.signal(signal.SIGINT, signal_handler)

   while True:     
      localtime = time.localtime()
      timeString  = time.strftime("%Y%m%d%H%M%S", localtime)
      
      filename1 = 'mesowest.out.' + timeString + '.gz'
      cmd = "wget http://mesowest.utah.edu/data/mesowest.out.gz -O " + filename1
      print cmd
      rc = call(cmd, shell=True)
      
      filename2 = 'mesowest_csv.tbl.' + timeString + '.gz'
      cmd = "wget http://mesowest.utah.edu/data/mesowest_csv.tbl.gz -O " + filename2
      print cmd
      rc = call(cmd, shell=True)
      
      time.sleep(900)
   return 0

if __name__  == '__main__':
   main()
